package com.xtjc03.domain.rest;

import com.xtjc03.domain.entity.Led;
import com.xtjc03.domain.service.impl.LedServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping(value="/api/led")
public class LedController {

    @Autowired
    LedServiceImpl ledService;

    @Value("${server.port}")
    String serverPort;

    @GetMapping("/start")
    public Led start(){
        return ledService.start();
    }

    @GetMapping("/stop")
    public Led stop(){
        return ledService.stop();
    }

    @GetMapping("/read")
    public Led read(){
        return ledService.read();
    }

    @GetMapping("/")
    public Map<String, String> route(){
        Map<String, String> map = new HashMap<>();
        map.put("打开Led", "http://127.0.0.1:" + serverPort + "/api/led/start");
        map.put("关闭Led", "http://127.0.0.1:" + serverPort + "/api/led/stop");
        map.put("读取Led状态", "http://127.0.0.1:" + serverPort + "/api/led/read");
        return map;
    }
}